<?php
namespace app\wechatxcx\controller;


use app\common\model\ChangguanChangdi;
use app\common\model\ChangguanFenleiChangdi;
use \app\common\model\Changguan as ChangguanModel;

use zjkal\ChinaHoliday;

class Index extends AllBase
{
    protected function initialize()
    {
        parent::initialize();
    }

    /**
     * 分页列表
     * @return \think\response\Json
     */
    public function list()
    {
        //查询条件
        $where = array();

        if (input('city')!='全部城市') {
            $where['city'] = input('city');
        }
        if (input('name')) {
            $where['name'] = array('like', "%" . input('name') . "%");
        }
        if (input('cate')!='全部') {
            $fl_where['label'] = array('eq',input('cate'));
            $fl_id  = ChangguanFenleiChangdi::getValue($fl_where,'id');
            $cg_ids = ChangguanChangdi::getColumn(array('flid'=>array('eq',$fl_id)),'cgid');
            $where['id'] = array('in',$cg_ids);
        }

        //分页信息
        $page = max(input('page'), 1);
        $size = input('size',20);
        //获取分页列表
        $list = ChangguanModel::getPage($where, $page, $size, 'id desc');
        //总页码
        $total = ChangguanModel::getCount($where);
        //数据返回
        if (!$list) {
            return returnJson(200, '', array('list' => [], 'total' => 0));
        }
        
        return returnJson(200, '', [
            'list' => $list,
            'total' => $total
        ]);
    }

    /**
     * 场馆-所有城市信息
     * @return \think\response\Json
     */
    public function allcity()
    {
        $data = ChangguanModel::getAllGroupby([],'city','city');
        if($data){
            $data = array_column($data,'city');
        }

        return returnJson(200, 'success', $data);
    }

    /**
     * 场馆-所有分类信息
     * @return \think\response\Json
     */
    public function allcate()
    {
        $data = ChangguanFenleiChangdi::getColumn(['pid'=>0],'label');

        return returnJson(200, 'success', $data);
    }

}